<template>
  <div>
    <el-tree
      ref="refTree"
      :props="{label:'name'}"
      default-expand-all
      :show-checkbox="true"
      :check-strictly="true"
      :data="list"
      node-key="id"
    />
    <div>
      <el-button size="small" type="primary" @click="hSubmit">确定</el-button>
      <el-button size="small">取消</el-button>
    </div>
  </div>
</template>

<script>
import { getPermissionList } from '@/api/permission'
import { getTreeData } from '@/utils'
import { assignPrem, getRoleDetail } from '@/api/settings'
export default {
  props: {
    curId: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      list: []
      // permIds: []
    }
  },
  created() {
    this.doAssign()
  },
  methods: {
    async  hSubmit() {
      const permIds = this.$refs.refTree.getCheckedKeys()
      const res = await assignPrem({ id: this.curId, permIds })
      this.$message.success(res.message)
      this.$emit('success')
    },
    async  doAssign() {
      this.showassignPermission = true
      const res = await getPermissionList()
      // console.log(res)
      this.list = getTreeData(res.data)
      const detail = await getRoleDetail(this.curId)
      // console.log(detail)
      // this.permIds = detail.data.permIds
      this.$refs.refTree.setCheckedKeys(detail.data.permIds)
    }
  }
}
</script>
